#include <iostream>
#include <cfloat>

bool hmean(double a, double b, double *ans);

int main()
{
    double x, y, z;

    std::cout << "Enter two numbers <q to quit>: ";
    while (std::cin >> x && std::cin >> y)
    {
        if (hmean(x, y, &z))
        {
            std::cout << "Harmonic mean of " << x << " and " << y
                      << " is " << z << std::endl;
        }
        else
        {
            std::cout << "One value should not be the negative "
                      << "of the other - try again.\n";
        }
        std::cout << "Enter two numbers <q to quit>: ";
    }
    std::cout << "Done.\n";

    return 0;
}

bool hmean(double a, double b, double *ans)
{
    if (a == -b)
    {
        *ans = DBL_MAX;
        return false;
    }
    else
    {
        *ans = (2.0 * a * b) / (a + b);
        return true;
    }
}
